import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import Vuex from "vuex";
import "element-ui/lib/theme-chalk/index.css";
import Mock from "./mock"; //引入后就会拦截所有http请求
Mock.bootstrap(); //申明配置

Vue.use(ElementUI)
Vue.use(Vuex)

// 路由连接过滤
router.beforeEach((to,from,next) =>{
  if (to.path === '/login'){
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login' ){
    next({path:'/login'});
  } next();
})

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
